﻿using System;
using System.Drawing;
using System.IO;

namespace Microsoft.WowAddonStudio.FrameXml.Formats.Blp
{
    /// <summary>
    /// Provides static methods to load a BLP image from a file or from a stream.
    /// </summary>
    public static class BlpImage
    {
        /// <summary>
        /// Loads a BLP image from the given path.
        /// </summary>
        /// <param name="path">The path of the BLP image.</param>
        /// <returns>An instance of the <see cref="Image"/> class.</returns>
        public static Image FromFile(string path)
        {
            if (path == null)
                throw new ArgumentNullException("path");

            using (Stream stream = File.Open(path, FileMode.Open, FileAccess.Read))
            {
                return BlpImage.FromStream(stream);
            }
        }

        /// <summary>
        /// Loads a BLP image from a stream.
        /// </summary>
        /// <param name="stream">The stream to load the BLP image from.</param>
        /// <returns>An instance of the <see cref="Image"/> class.</returns>
        public static Image FromStream(Stream stream)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");

            // Open the BLP file from the stream
            var blpFile = new BlpFile(stream);

            // Get the original image
            return blpFile.OriginalImageMipMap.GetImage();
        }
    }
}
